package demo.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//本类可替代为：
//        过滤器类加注解@WebFilter(urlPatterns = "/*")，
//        启动类加注解@ServletComponentScan

@Configuration
public class MyFilterConfig {

    @Bean
    public FilterRegistrationBean<MyFilter> loggingFilter(){
        FilterRegistrationBean<MyFilter> registrationBean 
          = new FilterRegistrationBean<>();

        registrationBean.setFilter(new MyFilter());
        registrationBean.addUrlPatterns("/*");

        return registrationBean;    
    }
}